from google.appengine.ext import db, webapp
from google.appengine.ext.webapp.util import run_wsgi_app

#Applicant Data Model Classes
class ApplicantStub(db.Model):
    password = db.TextProperty() #required=True)
    first_name = db.TextProperty() #required=True)
    middle_initial = db.TextProperty()
    last_name = db.TextProperty() #required=True)
    cell_phone_number = db.PhoneNumberProperty() #required=True)
    email_address = db.EmailProperty()
    security_question_answer = db.TextProperty()
    email_or_text = db.TextProperty() #required=True)
    comments = db.TextProperty(indexed=False)

class AddressStub(db.Model):
    applicant_address = db.TextProperty() #required=True)
    home_phone_number = db.PhoneNumberProperty() #required=True)
    comments = db.TextProperty(indexed=False)

class VitalsStub(db.Model):
	parent_entity = db.TextProperty()
	SSN = db.TextProperty()
	DOB = db.TextProperty()
	comments = db.TextProperty(indexed=False)
	
class DriversLicenceStub(db.Model):
	DLN = db.TextProperty()
	DL_IssueState = db.TextProperty()

class EducationStub(db.Model):
	parent_entity = db.TextProperty()
	educational_institution1 = db.TextProperty()
	educational_institution2 = db.TextProperty()
	educational_location1 = db.TextProperty()
	educational_location2 = db.TextProperty()
	degree1 = db.TextProperty()
	degree2 = db.TextProperty()
	last_attended1 = db.TextProperty()
	last_attended2 = db.TextProperty()
	graduated1 = db.TextProperty()
	graduated2 = db.TextProperty()
	comments = db.TextProperty(indexed=False)
	
class EmploymentStub(db.Model):
	parent_entity = db.TextProperty()
	employer_name1 = db.TextProperty()
	employer_phone_number1 = db.PhoneNumberProperty()
	employer_location1 = db.PostalAddressProperty()
	employee_position1 = db.TextProperty()
	date_started1 = db.TextProperty()
	date_ended1 = db.TextProperty()
	current_position1 = db.TextProperty()
	employer_name2 = db.TextProperty()
	employer_phone_number2 = db.PhoneNumberProperty()
	employer_location2 = db.PostalAddressProperty()
	employee_position2 = db.TextProperty()
	date_started2 = db.TextProperty()
	date_ended2 = db.TextProperty()
	current_position2 = db.TextProperty()
	employer_name3 = db.TextProperty()
	employer_phone_number3 = db.PhoneNumberProperty()
	employer_location3 = db.PostalAddressProperty()
	employee_position3 = db.TextProperty()
	date_started3 = db.TextProperty()
	date_ended3 = db.TextProperty()
	current_position3 = db.TextProperty()

#GetStarted page - First Page of Info Gathering
class GetStarted(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        self.response.out.write('''
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="em">
<html>
	<head>		
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
		<title>ResEdge - Get Started Page 1</title>
		<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
	</head>
	<body id="tab2">
	<img src="/Images/RawHeader1100.gif" />
	<ul id="tabnav">
	<li class="tab1"><a href="/">Home</a></li>
	<li class="tab2"><a href="/getstarted">Get Started</a></li>
	<li class="tab3"><a href="/retrieveresults">Retrieve Results</a></li>
	<li class="tab4"><a href="/admin/">Employers Portal</a></li>
	<li class="tab5"><a href="/admin/">F.A.Q.</a></li>
	<li class="tab6"><a href="/admin/">About ResEdge</a></li>
	</ul>
<h2>Distinguish Yourself And Your Resume with a ResEdge Report!</h2>
OK, let's get a Name and Password for you<br>
<form id="frmFirstForm" action="/postappstub" method="post" name="frmElecConsent">
First Name: <input type="text" name="txtFirstName" /> Middle Initial: <input type="text" name="txtMiddleInitial" /> Last Name: <input type="text" name="txtLastName" /><br>
What Password Would You Like To Use: <input type="password" name="txtPassword" /><br><br>
Alright, now a phone number and email address:<br>
Cell Phone #: <input type="tel" name="inPhoneNumber" /> Email Address: <input type="text" name="txtEmailAdd" /><br>
Would you rather have messages from us go to Email or Text Message to Cell Phone? <input type="radio" name="selMessage" value="Email" checked="selected" /> Email<input type="radio" name="selMessage" value="CellPhone" /> Cell Phone<br>
<hr>Please select a Security Question and provide an Answer:<br>
<select name="txtSecQuestion"><option value="1">Mothers' Maiden Name:</option><option value="2">Favorite Color:</option><option value="3">Favorite Season:</option><option value="4">Favorite Month:</option></select> Answer: <input type="text" name="txtSecQuestionAnswer" />
<input type="submit" name="btnSubmitFirstSheet" value="Next" />
</form>
<a href="/show">Show Entities</a></p>
<a href="/admin/">Admin Page</a></p>
<hr>
<p>Click the <button type=button id="btnFinGetStarted" style="color:blue" onClick="location.href='/firstfrm'"/>Finished!</button> button to Submit Your ResEdge Information.</p>
<p>Copyright 2011 by ResEdge LLC, All rights Reserved.  ResEdge is trademarked by ResEdge LLC  Terms and Conditions  Privacy Policy</p> 
</body>
</html>
	''')
#End of GetStarted Page
        
#START: ShowEntitiesPage
class ShowEntities(webapp.RequestHandler):
    def get(self):
        self.response.headers["Content-Type"] = "text/html"
        self.response.out.write("""<html><head><title>ResEdge Show Entities Test Page</title></head>
           <body><p>This is the Show Entities Page!<p><hr><ol>""")
        # Output a list of ApplicantStub entities
        q = ApplicantStub.all()
        for applicants in q:
        	self.response.out.write("<p>Name: %s<br>Email Address: %s</p>" % (applicants.first_name, applicants.email_address))
#        q = db.GqlQuery('SELECT * From ApplicantStub')
        self.response.out.write("""</ol><hr><p><a href="/getstarted">GetStarted Page</a></p></body></html>""")
#END: ShowEntitiesPage 

#Constructor & Posting Of Data
class PostApplicantStub(webapp.RequestHandler):
    def post(self):
    	applicant = ApplicantStub()
        applicant.password = self.request.get("txtPassword")
        applicant.first_name = self.request.get("txtFirstName")
        applicant.middle_initial = self.request.get("txtMiddleInitial")
        applicant.last_name = self.request.get("txtLastName")
        applicant.cell_phone_number = self.request.get("inPhoneNumber")
        applicant.email_address = self.request.get("txtEmailAdd")
        applicant.security_question_answer = (self.request.get("txtSecQuestion")+self.request.get("txtSecQuestionAnswer"))
        applicant.email_or_text = self.request.get("selMessage")
        applicant.comments = self.request.get("txtComments")
        applicant.put()
        self.redirect('/getstarted')
#        self.redirect('/admin/')

class PostAddressStub(webapp.RequestHandler):
	def post(self):
		address = AddressStub( #parent=applicant,
#		parent_entity = ApplicantStub.get_by_key_name('703-509-2507'),
		applicant_address = ("Add :"+self.request.get("txtStreetAdd1")+", "+self.request.get("txtStreetAdd2")+", "+
		    				 self.request.get("txtCity")+", "+self.request.get("txtState")+", "+self.request.get("txtZip+4")),
		home_phone_number = self.request.get("txtCurHomePhone"),
		comments = self.request.get("txtComments"))
		address.put()
		vitals = VitalsStub( #parent=applicant,
#		parent_entity = ApplicantStub.get_by_key_name('703-509-2507'),
		SSN = self.request.get("txtSSN"),
		DOB = self.request.get("txtDOB"),
		comments = self.request.get("txtComments"))
		vitals.put()
		driverslicense = DriversLicenceStub( #parent=applicant,
#		parent_entity = ApplicantStub.get_by_key_name('703-509-2507'),
		DLN = self.request.get("txtDriversLicenseNumber"),
		DL_IssueState = self.request.get("txtDLIssuedBy"))
		driverslicense.put()
		self.redirect('/GetStarted3')

class PostEducationStub(webapp.RequestHandler):
    def post(self):
        schoolin = EducationStub( #parent=applicant
#        parent_entity = ApplicantStub.get_by_key_name('703-509-2507'),
        educational_institution1 = self.request.get("txtUniName1"),
        educational_location1 = self.request.get("txtUniLocation1"),
        degree1 = self.request.get("txtUniCourse1"),
        last_attended1 = self.request.get("txtUniYear1"),
        graduated1 = self.request.get("bolUniGrad1"),
        educational_institution2 = self.request.get("txtUniName2"),
        educational_location2 = self.request.get("txtUniLocation2"),
        degree2 = self.request.get("txtUniCourse2"),
        last_attended2 = self.request.get("txtUniYear2"),
        graduated2 = self.request.get("bolUniGrad2"))
        schoolin.put()
        self.redirect('/GetStarted4')
        
class PostEmploymentStub(webapp.RequestHandler):
    def post(self):
        employment = EmploymentStub( #parent=applicant
#        parent_entity = ApplicantStub.get_by_key_name('703-509-2507'),
        employer_name1 = self.request.get("txtEmpName1"),
        employer_phone_number1 = self.request.get("txtEmpPhoneNumber1"),
        employer_location1 = self.request.get("txtEmpLocation1"),
        employee_position1 = self.request.get("txtEmpPosition1"),
        date_started1 = self.request.get("txtEmpStart1"),
        date_ended1 = self.request.get("txtEmpEnd1"),
        current_position1 = self.request.get("selEmpCurrent1"),
        employer_name2 = self.request.get("txtEmpName2"),
        employer_phone_number2 = self.request.get("txtEmpPhoneNumber2"),
        employer_location2 = self.request.get("txtEmpLocation2"),
        employee_position2 = self.request.get("txtEmpPosition2"),
        date_started2 = self.request.get("txtEmpStart2"),
        date_ended2 = self.request.get("txtEmpEnd2"),
        current_position2 = self.request.get("selEmpCurrent2"),
        employer_name3 = self.request.get("txtEmpName3"),
        employer_phone_number3 = self.request.get("txtEmpPhoneNumber3"),
        employer_location3 = self.request.get("txtEmpLocation3"),
        employee_position3 = self.request.get("txtEmpPosition3"),
        date_started3 = self.request.get("txtEmpStart3"),
        date_ended3 = self.request.get("txtEmpEnd3"),
        current_position3 = self.request.get("selEmpCurrent3"))        
        employment.put()
        self.redirect('/stylesheets/RetrieveResults.html')

application = webapp.WSGIApplication([
    ('/', GetStarted),
    ('/getstarted', GetStarted),
    ('/postappstub', PostApplicantStub),
    ('/show', ShowEntities),
], debug=True)

def main():
    run_wsgi_app(application)

if __name__ == '__main__':
    main()